# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: execute.py
# Time: 17:40

import time

from common.element.browser import AcquireBrowser
from common.element.element import WebTools
from common.utils.file_util import get_data_newtheme
from common.utils.read_util import OperationYaml
from page.netheme.handler import NewthemeHandler


class NethemeBiz():
    def __init__(self, driver, log):
        self.__log = log
        self.__driver = WebTools(driver, log)
        self.handler = NewthemeHandler(driver, log)
        self.explain = OperationYaml("new_theme.yaml")
        self.upload = AcquireBrowser(driver, log)

    def add_the_theme(self, topicname, theme_img, introduce, market_price, sales_price, experiential_price, *args):
        '''
        增加主题
        :param topicname: 主题名称
        :param theme_img: 主题图片
        :param introduce: 主题介绍
        :param market_price: 市场价
        :param sales_price: 销售价
        :param experiential_price: 体验价
        :return:
        '''
        self.__driver.click_element(self.handler.get_haibaodushujulebu(),
                                    self.explain.get_annotation("haibaodushujulebu"))
        self.__driver.click_element(self.handler.get_yuedulibao(), self.explain.get_annotation("yuedulibao"))
        self.__driver.click_element(self.handler.get_zhutiguanli(), self.explain.get_annotation("zhutiguanli"))
        self.__driver.click_element(self.handler.get_xinzengzhuti(), self.explain.get_annotation("xinzengzhuti"))
        time.sleep(2)
        self.__driver.input_vlaue(self.handler.get_zhutimingcheng(), topicname,
                                  self.explain.get_annotation("zhutimingcheng"))
        self.__driver.click_element(self.handler.get_zhutitupian(), self.explain.get_annotation("zhutitupian"))
        time.sleep(2)
        self.upload.upload_files(get_data_newtheme(f"{theme_img}.png"))
        self.__driver.switch_iframe(self.handler.get_iframe_zhutijieshao(),self.explain.get_annotation("iframe_zhutijieshao"))
        self.__driver.input_vlaue(self.handler.get_zhutijieshao(), introduce,
                                  self.explain.get_annotation("iframe_zhutijieshao"))
        self.__driver.switch_the_main_document()
        # self.__driver.click_element(self.handler.get_shangchauntupian(),self.explain.get_annotation("shangchauntupian"))
        # self.__driver.click_element(self.handler.get_xuanzetupian(),self.explain.get_annotation("xuanzetupian"))
        # self.upload.upload_files(get_data_newtheme(f"{theme_img}.jpg"))
        self.__driver.input_vlaue(self.handler.get_shichangjia(), market_price,
                                  self.explain.get_annotation("shichangjia"))
        self.__driver.input_vlaue(self.handler.get_xiaoshoujia(), sales_price,
                                  self.explain.get_annotation("xiaoshoujia"))
        self.__driver.input_vlaue(self.handler.get_tiyanjia(), experiential_price,
                                  self.explain.get_annotation("tiyanjia"))



if __name__ == '__main__':
    from page.login.execute import LoginBiz
    from selenium import webdriver
    from common.utils.log_util import logger

    log = logger()
    driver = webdriver.Chrome()
    driver.get("https://college-admin.baobaobooks.net/login")
    driver.maximize_window()
    driver.implicitly_wait(10)
    LoginBiz(driver, log).login("邓先庭", "dxt123456")
    NethemeBiz(driver, log).add_the_theme("测试", "主题图片", "介绍", "12", "13", "14")
